﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using MVVMWrapper;

namespace MVVM_Wrapper_Test {
   /// <summary>
   /// Is a view model collection that wraps a business collection. 
   /// This collection manages changes, if a business object gets added to the Source collection this collection will get the newly added item 
   /// and 'wrap' it in a ViewModel item.
   /// </summary>
   public class PersonViewModelCollection : WrappedObservableCollection<Person, PersonViewModel> {

      public PersonViewModelCollection(ObservableCollection<Person> personBusinessCollection)
         : base((Person person) => {
            //this is the method used to 'wrap' a person object in a PersonViewModel object
            return new PersonViewModel(person);
         }) {
         //now set the source collection, the base class will call the method above for any items in the colleciton at this time
         //also for any items added after 
         base.SourceCollection = personBusinessCollection;
      }
   }
}
